package com.hluck.goodweatherapp.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.hluck.goodweatherapp.data.bean.AirResponse;
import com.hluck.goodweatherapp.data.bean.HourlyResponse;
import com.hluck.goodweatherapp.data.bean.LocationData;
import com.hluck.goodweatherapp.data.bean.MyCity;
import com.hluck.goodweatherapp.data.bean.Province;
import com.hluck.goodweatherapp.data.bean.WeatherData;
import com.hluck.goodweatherapp.data.bean.WeatherIndexResponse;
import com.hluck.goodweatherapp.data.bean.WeekWeather;
import com.hluck.goodweatherapp.data.repository.CityRepository;
import com.hluck.goodweatherapp.data.repository.SearchCityRepository;
import com.hluck.goodweatherapp.data.repository.WeatherRepository;
import com.hluck.mvvmlibrary.base.BaseViewModel;

import java.util.List;

/**
 * @Author： LJH
 * @Time： 2023/12/28
 * @description：
 */
public class MainViewModel extends BaseViewModel {
    private SearchCityRepository searchCityRepository;
    private WeatherRepository weatherRepository;

    public MainViewModel() {
        this.searchCityRepository = SearchCityRepository.getInstance();
        this.weatherRepository = WeatherRepository.getInstance();

    }

    public MutableLiveData<LocationData> searchLiveData = new MutableLiveData<LocationData>();
    public MutableLiveData<WeatherData> weatherLiveData = new MutableLiveData<WeatherData>();
    public MutableLiveData<WeekWeather> weekWeatherLiveData = new MutableLiveData<WeekWeather>();
    public MutableLiveData<WeatherIndexResponse> lifeStyleLiveData = new MutableLiveData<WeatherIndexResponse>();
    public MutableLiveData<List<Province>> cityMutableLiveData = new MutableLiveData<>();

    public MutableLiveData<HourlyResponse> hourlyResponseMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<AirResponse> airResponseMutableLiveData = new MutableLiveData<>();

    public void hourlyWeather(String cityId){
        WeatherRepository.getInstance().hourlyWeather(hourlyResponseMutableLiveData,failed,cityId);
    }

    public void airWeather(String cityId){
        WeatherRepository.getInstance().airWeather(airResponseMutableLiveData,failed,cityId);
    }

    public void getAllCity(){
        CityRepository.getInstance().getCityData(cityMutableLiveData);
    }

    /**
     * 搜索成功
     * @param cityName 城市名称
     * @param isExact 是否精准搜索
     */
    public void searchCity(String cityName,boolean isExact){
        searchCityRepository.searchCity(searchLiveData,failed,cityName,isExact);
    }


    /**
     * 查询实况天气
     * @param cityId
     */
    public void searchWeather(String cityId){
        weatherRepository.nowWeather(weatherLiveData,failed,cityId);
    }

    /**
     * 查询7天天气
     * @param cityId
     */
    public void dailyWeather(String cityId){
        weatherRepository.dailyWeather(weekWeatherLiveData,failed,cityId);
    }

    /**
     * 查询生活指数数据
     * @param cityId
     */
    public void lifeStyle(String cityId){
        weatherRepository.lifestyle(lifeStyleLiveData,failed,cityId);
    }

    /**
     * 添加我的城市数据，在定位之后添加数据
     * @param cityName
     */
    public void addMyCityData(String cityName){
        MyCity myCity = new MyCity(cityName);
        CityRepository.getInstance().addMyCityData(myCity);
    }
}
